<script setup lang="ts">
import { onMounted, ref } from "vue";
import Top from "@/views/screen/components/top/index.vue";
import Tourist from "@/views/screen/components/tourist/index.vue";
import Sex from "@/views/screen/components/sex/index.vue";
import Age from "@/views/screen/components/age/index.vue";
import Map from "@/views/screen/components/map/index.vue";
import Line from "@/views/screen/components/line/index.vue";
import Counter from "@/views/screen/components/counter/index.vue";
import Year from "@/views/screen/components/year/index.vue";
import Rank from "@/views/screen/components/rank/index.vue";

// 数据大屏内容区域
let screen = ref<HTMLElement | null>(null);

// 获取屏幕的缩放比例
const getScale = (w = 1920, h = 1080) => {
  const width = window.innerWidth;
  const height = window.innerHeight;
  const scaleX = width / w;
  const scaleY = height / h;
  return Math.min(scaleX, scaleY);
};

const resizeScreen = () => {
  // 获取屏幕的缩放比例
  const scale = getScale();
  // 设置屏幕的缩放比例
  screen.value!.style.transform = `scale(${scale})`;
  // 设置屏幕的偏移量
  screen.value!.style.marginLeft = `${-1920 / 2}px`;
  screen.value!.style.marginTop = `${-1080 / 2}px`;
};

onMounted(() => {
  resizeScreen();
});

// 监听屏幕的变化
window.onresize = () => {
  resizeScreen();
};

defineOptions({
  name: "Screen",
});
</script>

<template>
  <div class="container">
    <!--  数据大屏内容区域  -->
    <div class="screen" ref="screen">
      <!--  顶部    -->
      <div class="top">
        <Top></Top>
      </div>
      <!--  底部    -->
      <div class="bottom">
        <!--   左     -->
        <div class="left">
          <Tourist class="tourist"></Tourist>
          <Sex class="sex"></Sex>
          <Age class="age"></Age>
        </div>
        <!--   中    -->
        <div class="center">
          <Map class="map"></Map>
          <Line class="line"></Line>
        </div>
        <!--   右    -->
        <div class="right">
          <Rank class="rank"></Rank>
          <Year class="year"></Year>
          <Counter class="counter"></Counter>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.container {
  width: 100vw;
  height: 100vh;
  background: url("./images/bg.png") no-repeat;
  background-size: cover;

  .screen {
    position: fixed;
    width: 1920px;
    height: 1080px;
    left: 50%;
    top: 50%;
    .top {
      width: 100%;
      height: 50px;
    }
    .bottom {
      display: flex;
      .left {
        flex: 1;
        width: 100%;
        height: 1030px;
        display: flex;
        flex-direction: column; // 垂直排列
        .tourist {
          flex: 1.2;
        }
        .sex {
          flex: 1;
        }
        .age {
          flex: 1;
        }
      }
      .center {
        flex: 2;
        display: flex;
        flex-direction: column; // 垂直排列
        .map {
          flex: 2;
        }
        .line {
          flex: 1;
        }
      }
      .right {
        flex: 1.1;
        display: flex;
        flex-direction: column; // 垂直排列
        .rank {
          flex: 1.2;
        }
        .year {
          flex: 1;
        }
        .counter {
          flex: 1;
        }
      }
    }
  }
}
</style>
